package org.testis.gui.mvc.model.testdesign;

import org.testis.gui.mvc.model.*;
import org.testis.gui.mvc.controller.testdesign.CompareGUIController;
import org.testis.gui.mvc.controller.dynamicmap.DynamicMapTreeController;
import org.testis.gui.mvc.controller.testdesign.TreeController;
import org.testis.gui.mvc.utilities.ComparisonTreeNode;
import org.testis.gui.mvc.utilities.OperationExecutor;
import org.testis.utils.tree.MyDefaultMutableTreeNode;

/**
 *
 * @author Cahit Emir Erel
 */
public class CompareGUIModel extends AbstractModel{
    public static final String DEFAULT_OPERATION_MODE = CompareGUIController.DEFAULT_OPERATION_MODE;

    private ComparisonTreeNode m_source=null;
    private ComparisonTreeNode m_destination=null;
    private ComparisonTreeNode m_selectedSourceNode=null;
    private ComparisonTreeNode m_selectedDestinationNode=null;
    private String m_operationMode = DEFAULT_OPERATION_MODE;
    private Boolean m_showWindow = false;
    private String m_properties = "";
    private String m_sourceLabel = "";
    private String m_destinationLabel = "";
    private Boolean m_singleMode = true;
    private OperationExecutor m_executor=null;


    public ComparisonTreeNode getSource()
    {
        return m_source;
    }


    public void setSource(ComparisonTreeNode source)
    {
        ComparisonTreeNode oldSource = m_source;
        m_source = source;
        firePropertyChange(CompareGUIController.SOURCE,
                               oldSource,
                               source);
    }


    public ComparisonTreeNode getDestination()
    {
        return m_destination;
    }


    public void setDestination(ComparisonTreeNode destination)
    {
        ComparisonTreeNode oldDestination = m_destination;
        m_destination = destination;
        firePropertyChange(CompareGUIController.DESTINATION,
                               oldDestination,
                               destination);
    }


    public String getOperationMode()
    {
        return m_operationMode;
    }


    public void setOperationMode(String operationMode)
    {
        String oldOperationMode = m_operationMode;
        m_operationMode = operationMode;
        firePropertyChange(CompareGUIController.SELECT_MODE,
                               oldOperationMode,
                               operationMode);
    }


    public void setShowWindow(Boolean showWindow)
    {
        if (showWindow==null) {
            return;
        }
        Boolean oldShowWindow = m_showWindow;
        m_showWindow = showWindow;
        firePropertyChange(CompareGUIController.SHOW,
                               oldShowWindow,
                               showWindow);
    }


    public String getProperties()
    {
        return m_properties;
    }


    public void setProperties(String properties)
    {
        if (properties==null) {
            return;
        }
        String oldProperties = m_properties;
        m_properties = properties;
        firePropertyChange(CompareGUIController.PROPERTIES,
                               oldProperties,
                               properties);
    }
    
    public void setRefreshSrcTree(Boolean refresh) {
        if (refresh != null && refresh) {
            firePropertyChange(CompareGUIController.SRC_TREE_SRC_REFRESH,
                               false,
                               true);
        }
    }
    
    public void setRefreshDstTree(Boolean refresh) {
        if (refresh != null && refresh) {
            firePropertyChange(CompareGUIController.DST_TREE_REFRESH,
                               false,
                               true);
        }
    }
    
    public void setHighlight(MyDefaultMutableTreeNode node) {
        if (node != null) {
            firePropertyChange(CompareGUIController.HIGHLIGHT_NODE,
                               null,
                               node);
        }
    }
    
    public OperationExecutor getExecutor() {
        return m_executor;
    }
    
    public void setExecutor(OperationExecutor executor) {
        m_executor = executor;
    }
    
    public void setExecutor(TreeController executor) {
        setExecutor((OperationExecutor)executor);
    }
    
    public void setExecutor(DynamicMapTreeController executor) {
        setExecutor((OperationExecutor)executor);
    }
    
    public void setHighlight(ComparisonTreeNode node) {
        setHighlight((MyDefaultMutableTreeNode)node);
    }
    
    public void setUnHighlight(MyDefaultMutableTreeNode node) {
        if (node != null) {
            firePropertyChange(CompareGUIController.UN_HIGHLIGHT_NODE,
                               null,
                               node);
        }
    }
    
    public void setUnHighlight(ComparisonTreeNode node) {
        setUnHighlight((MyDefaultMutableTreeNode)node);
    }

    public void setRemoveOperation(ComparisonTreeNode removedNode) {
        if (removedNode != null) {
            firePropertyChange(CompareGUIController.REMOVE_OPERATION,
                               null,
                               removedNode);
        }
    }
    
    public void setAddOperation(ComparisonTreeNode addedNode) {
        if (addedNode != null) {
            firePropertyChange(CompareGUIController.ADD_OPERATION,
                               null,
                               addedNode);
        }
    }

    public ComparisonTreeNode getSelectedSourceNode()
    {
        return m_selectedSourceNode;
    }


    public void setSelectedSourceNode(ComparisonTreeNode selectedSourceNode)
    {
        //ComparisonTreeNode oldSelectedSourceNode = m_selectedSourceNode;
        m_selectedSourceNode = selectedSourceNode;
        firePropertyChange(CompareGUIController.SELECT_SOURCE_NODE,
                               null,
                               selectedSourceNode);
    }


    public ComparisonTreeNode getSelectedDestinationNode()
    {
        return m_selectedDestinationNode;
    }


    public void setSelectedDestinationNode(ComparisonTreeNode selectedDestinationNode)
    {
        //ComparisonTreeNode oldSelectedDestinationNode = m_selectedDestinationNode;
        m_selectedDestinationNode = selectedDestinationNode;
        firePropertyChange(CompareGUIController.SELECT_DESTINATION_NODE,
                               null,
                               selectedDestinationNode);
    }


    public String getSourceLabel()
    {
        return m_sourceLabel;
    }


    public void setSourceLabel(String sourceLabel)
    {
        String oldSourceLabel = m_sourceLabel;
        m_sourceLabel = sourceLabel;
        firePropertyChange(CompareGUIController.SRC_LABEL,
                               oldSourceLabel,
                               sourceLabel);
    }


    public String getDestinationLabel()
    {
        return m_destinationLabel;
    }


    public void setDestinationLabel(String destinationLabel)
    {
        String oldDestinationLabel = m_destinationLabel;
        m_destinationLabel = destinationLabel;
        firePropertyChange(CompareGUIController.DST_LABEL,
                               oldDestinationLabel,
                               destinationLabel);
    }


    public Boolean getSingleMode()
    {
        return m_singleMode;
    }


    public void setSingleMode(Boolean singleMode)
    {
        Boolean oldSingleMode = m_singleMode;
        m_singleMode = singleMode;
        firePropertyChange(CompareGUIController.SINGLE_MODE,
                               oldSingleMode,
                               singleMode);
    }
}
